package com.anyisn.anyflickr.shell.view.components.popup
{
	import flash.events.MouseEvent;
	
	import mx.containers.HBox;
	import mx.containers.TitleWindow;
	import mx.containers.VBox;
	import mx.controls.Label;
	
	import com.anyisn.anyflickr.common.events.DownloadEvent;
	import com.anyisn.anyflickr.shell.view.components.itemrender.PhotoSizeLB;
	
	public class PhotoSizes extends TitleWindow
	{
		
		public static const DOWNLOAD:String = "download";
		private var _sizes:Array;
		
		public function PhotoSizes(sizes:Array = null)
		{
			_sizes = sizes;
			super();
			this.title = "Choose Size";
			this.showCloseButton = true;
			init();
		}
		
		private function init():void {
			if(_sizes) {
				var vb:VBox = new VBox();
				for(var i:int=0;i<_sizes.length;i++) {
					var lb:PhotoSizeLB = new PhotoSizeLB();
					lb.width = 100;
					lb.label = _sizes[i].label;
					lb.source = _sizes[i].source;
					lb.addEventListener(MouseEvent.CLICK, download);
					var hb:HBox = new HBox();
					var label:Label = new Label();
					label.text = _sizes[i].width + 'x' + _sizes[i].height;
					hb.addChild(lb);
					hb.addChild(label);
					vb.addChild(hb);
				}
				addChild(vb);
			}
		}
		
		private function download(e:MouseEvent):void {
			dispatchEvent(new DownloadEvent(DOWNLOAD, e.target.source));
			
		}
		
		public function set sizes(data:Array):void {
			_sizes = data;
			init();
		}
	}
}